﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;

namespace GPCSC.Web
{
    public class HashtableAndDatatable
    {
        public HashtableAndDatatable()
        { 
        
        }
        /// <summary>
        /// Hashtable转化成table
        /// </summary>
        /// <param name="htable"></param>
        /// <returns></returns>
        public static  DataTable Retable(Hashtable htable)
        {
            DataTable tables = new DataTable();
            foreach (DictionaryEntry de in htable)
            {
                tables.Columns.Add(de.Key.ToString(), typeof(string));
                if (tables.Rows.Count <= 0)
                {
                    tables.Rows.Add(de.Value);
                }
                else
                {
                    if (de.Value == null)
                        tables.Rows[0][de.Key.ToString()] = DBNull.Value;
                    else
                        tables.Rows[0][de.Key.ToString()] = de.Value;
                }

            }
            return tables;
        }
    }
}